package com.movie.playvideos.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.movie.playvideos.R;
import com.movie.playvideos.model.Category;

public class CustomMenuAdapter extends ArrayAdapter<Category>{

	private List<Category> mListCategory;
	private Context mContext;
	
	public CustomMenuAdapter(Context context, int resource, List<Category> objects) {
		super(context, resource, objects);
		
		mListCategory = objects;
		mContext = context;
	}

	@Override
	public int getCount() {
		return mListCategory.size();
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder hoder = new ViewHolder();
		
		if (convertView == null) {
			LayoutInflater inflater = LayoutInflater.from(mContext);
			convertView = inflater.inflate(R.layout.row, null);
			
			hoder.iconID = (ImageView) convertView.findViewById(R.id.row_icon);
			hoder.name = (TextView) convertView.findViewById(R.id.row_title);
			
			convertView.setTag(hoder);
		} else {
			hoder = (ViewHolder) convertView.getTag();
		}
		
		Category item = mListCategory.get(position);
		hoder.iconID.setImageResource(item.getIconID());
		hoder.name.setText(item.getName());
		
		return convertView;
	}
	
	
	 static class ViewHolder {
		 ImageView iconID;
		 TextView name;
	}
}
